package edu.ynu.se.xiecheng.achitectureclass.entity;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.annotations.Where;
import edu.ynu.se.xiecheng.achitectureclass.entity.User;
import org.springframework.util.DigestUtils;

import javax.persistence.*;

@Entity
@Getter
@Setter
@Inheritance
@Where(clause = "is_deleted = 0")
@DiscriminatorColumn(name = "type")
@NoArgsConstructor
@DiscriminatorValue("1")
public class GHUser extends User {

    @Column
    protected String username;

    @Column
    protected String password;
    @Column
    protected String role;
    public String getHasRole(){
        return role;
    }
    /**
     * 创建所有User时，密码经过md5加密
     * @param psd
     */
    public void setPassword(String psd){
        this.password = DigestUtils.md5DigestAsHex(psd.getBytes());
    }

    @Column(updatable = false, insertable = false)
    protected Integer type;
}